<template>
  <el-dialog :visible="showRoleDialog" title="角色分配" @close="cancelBtn">
    <el-checkbox-group v-model="checkList">
      <el-checkbox v-for="item in roleList" :key="item.id" :label="item.id">{{
        item.name
      }}</el-checkbox>
    </el-checkbox-group>

    <!-- 定义footer插槽 -->
    <el-row slot="footer" type="flex" justify="center">
      <el-col :span="6">
        <el-button type="primary" size="samll" @click="isOkBtn">确定</el-button>
        <el-button size="samll" @click="cancelBtn">取消</el-button>
      </el-col>
    </el-row>
  </el-dialog>
</template>

<script>
import { getRoleList } from "@/api/setting";
import { getStaffInfo } from "@/api/user";
import { assignRoles } from "@/api/employees";
export default {
  props: {
    showRoleDialog: {
      type: Boolean,
      default: false,
    },
    userId: {
      type: String,
      //   required: true,
    },
  },

  data() {
    return {
      roleList: [],
      checkList: [],
    };
  },
  created() {
    this.getRoleList();
  },
  methods: {
    //获取所有角色信息渲染复选框
    async getRoleList() {
      const { rows } = await getRoleList({ page: 1, pagesize: 30 });
      this.roleList = rows;
    },
    // 根据ID获取点击用户的角色信息
    async getStaffInfo(id) {
      const { roleIds } = await getStaffInfo(id);
      this.checkList = roleIds;
    },
    isOkBtn() {
      assignRoles({ id: this.userId, roleIds: this.checkList });
      this.$emit("update:showRoleDialog", false);
    },
    cancelBtn() {
      this.checkList = [];
      this.$emit("update:showRoleDialog", false);
    },
  },
};
</script>

<style>
</style>